home *** CD-ROM | disk | FTP | other *** search
- Path: news.iastate.edu!mlrivas
- From: mlrivas@iastate.edu (Matthew L Rivas)
- Newsgroups: comp.lang.c++
- Subject: Overiding [] for C++ matrix class
- Date: 3 Apr 1996 15:54:23 GMT
- Organization: Iowa State University, Ames, Iowa USA
- Message-ID: <4ju6vf$kop@news.iastate.edu>
- NNTP-Posting-Host: burn.cce.iastate.edu
- Originator: mlrivas@burn.cce.iastate.edu
-
-
- I'm attempting to write a simple matrix class which will
- allow me to use the `[]' to access the matrix coefficients.
- The method I use is the follwing:
-
- virtual double * operator[](short r) {return coef[r];}
-
- which I found in a book. I derived a symmetric matrix class
- from this base. In the symmetric class, I only store the
- upper triangular coefficients to save memory (my work
- is extrememly memory intensive so this is necessary). I have an
- access function which checks the called for position and
- returns the correct coefficient, and it looks like:
-
- double symmatrix::getValue(short i,short j)
- {
- if (j >= i) return coeff[i][j];
- else return coeff[j][i];
- }
-
- I would like to have the same access function method, i.e., using `[]',
- for the symmetric class as well.
-
- I have two questions:
-
- 1) Is there a way to use `[]' for the symmetric class?
-
- 2) How exactly does the first routine work? I've never been sure
- and would really like to know.
-
- Any help would be appreciated. I do know about overloading the
- function calling operators `()' so that
-
- Matrix A(n,n);
- A(i,j) = 1.0;
- x = A(i,j);
-
- which is the same as the fortran calling convention. I don't really
- want to implement it this way and would rather stick with the C++
- standard if I can.
-
- Matthew Rivas
- mlrivas@iastate.edu
-